{include file="admin@public/header"/}

<link rel="stylesheet" href="/public/static/admin/css/report.css" />
<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">
<!-- <link rel="stylesheet" type="text/css" href="/public/static/admin/easyui/jeasyui/themes/icon.css"> -->
<style>
	.ui-icon-ellipsis {
		right: 5px;
	}

	#filter-menu .con {
		width: 355px;
	}

	#filter-menu label.tit {
		width: 80px;
	}

	/*.ui-jqgrid tr.jqgrow td {
	white-space: normal !important;
	}
	*/
	.no-query {
		background: url("/public/static/admin/css/img/no_query.png") no-repeat scroll 100px 60px #fff;
		background-position: center;
		border: 1px solid #ddd;
		border-top: none;
		height: 402px;
		margin-right: 0;
	}

	.box-flex {
		overflow: hidden;
		zoom: 1;
	}

	.box-flex .flex {
		float: left;
		width: 33.3%;
	}

	.grid-title {
		font-size: 24px;
		text-align: center;
		clear: none;
	}

	.ui-print .grid-wrap {
		padding: 10px 0 0 30px;
	}

	#conditions-trigger {
		background: url(/public/static/admin/css/img/bg.png) no-repeat;
		border: 0px;
		width: 74px;
		box-shadow: 0px 0px;
	}

	#filter-menu .conditions-trigger>b {
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -8px;
		width: 16px;
		height: 16px;
		background: url(/public/static/admin/css/img/down.png) 2px 5px no-repeat;
	}

	#filter-menu .conditions-trigger>b.act {
		background: url(/public/static/admin/css/img/up.png) 2px 5px no-repeat;
	}

	#filter-menu .btns {
		position: absolute;
		top: 7px;
		right: 0px;
	}

	.layui-form-checkbox[lay-skin=primary] i {
		padding: 0;
	}

	.layui-form-checked[lay-skin=primary] i {
		border-color: #5dc5e7;
		background-color: #5dc5e7;
		color: #fff;
		padding: 0;
	}

	.layui-form-checkbox[lay-skin=primary]:hover i {
		border-color: #5dc5e7;
	}

	.ui-droplist-wrap {
		height: auto;
	}

	#filterItems {
		height: auto;
	}
</style>

<div class="wrapper">
	<!-- header -->
	<div class="mod-search cf">
		<div class="l  layui-form" id="filter-menu">
			<ul class="ul-inline fix" id="filterItems" style="font-size: 12px;">
				<li id="date" style="display: list-item;"><label>单据日期:</label>
					<input type="date" id="startdate" class="ui-input " value="{$month.month_start|date='Y-m-d',###}" style="width: 125px;">
					<span class="todate"> 至 </span>
					<input type="date" id="enddate" class="ui-input " value="{$month.month_end|date='Y-m-d',###}" style="width: 125px;">
				</li>
				<li id="sale-rank-filter"><span id="sale-rank-catorage"></span></li>
				
                <!-- 选择商品 -->
				{include file="admin@select/goods"/}

				<!-- 选择客户 -->
				{include file="admin@select/customer"/}

				
                <!-- 选择商品类别 -->
				{include file="admin@select/goods_category"/}

				 <!-- 选择仓库 -->
				{include file="admin@select/store"/}
                <li class="chk-list" style="display: list-item;padding-top: 12px;">
                    <input type="checkbox" name="profit" id="chk-wrap" lay-skin="primary" title="计算毛利" value="0">
                    <div class="btns" style="top: -4px;position: relative;float: right;margin-top: 0;"><a class="ui-btn mrb ui-btn-search" id="filter-submit">查询</a>
					</div>
                </li>



				<!-- <span class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5713" target="_blank" class="video-icon" style="margin-right: 5px;"></a>功能简介</span> -->
			</ul>
			<!-- <a href="#" id="conditions-trigger" class="ui-btn conditions-trigger" tabindex="-1">&nbsp;更多条件<b></b></a> -->
		</div>
	</div>

	  <!-- 下拉树选择（商品类别） -->
	{include file="admin@popup/goods_category"/}

	<!-- no data -->
	<div class="no-query"></div>
	<!-- grid begin -->
	<div class="ui-print" id="ui-print" style="visibility: hidden;">
		<!-- 列配置 -->
		<div class="cf box-flex">
			<div class="flex">
				<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>

			<div class="grid-title flex">销售汇总表（按商品）</div>
			<div class="fr">
				<a href="#" class="ui-btn ui-btn-export btn-sm mrb fl" id="btn-export">导出</a>
				<a href="javascript:void(0)" class="ui-btn ui-btn-print btn-sm fl" id="btn-print"
					onclick="preview(1)">打印</a>
			</div>
		</div>

		<div class="grid-wrap" id="grid-wrap" style="padding-bottom: 30px;padding-right: 30px;">
			<!--startprint-->
			<!-- <div class="grid-title">销售汇总表（按商品）</div> -->
			<div class="grid-subtitle"></div>
			<table id="grid"></table>
			<!--endprint-->
			<div id="page"></div>
		</div>
	</div>
	<!-- grid end -->
</div>

<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
	function preview(oper) {
		if (oper < 10) {
			$("#grid-wrap").jqprint();
		} else {
			window.print();
		}
	}
</script>


<script type="text/javascript">

	$(document).ready(function () {

		// 点击查询按钮
		$("#filter-submit").click(function () {
			$("#ui-print").css({ "visibility": "visible" });  //显示表格数据
			$(".no-query").hide();  //隐藏提示

			// 设置表格高度
			$("#grid").setGridHeight($(window).height()-230-$("#filter-menu").height()+"px");

            // 判断是否勾选计算毛利（勾选计算毛利，显示字段单位成本、销售成本、销售毛利、毛利率）
            if ($("#chk-wrap").get(0).checked) {
                $("#grid").setGridParam().showCol("danweichengben");
                $("#grid").setGridParam().showCol("xiaoshouchengben");
                $("#grid").setGridParam().showCol("xiaoshoumaoli");
                $("#grid").setGridParam().showCol("maolilv");
            }else{
                $("#grid").setGridParam().hideCol("danweichengben");
                $("#grid").setGridParam().hideCol("xiaoshouchengben");
                $("#grid").setGridParam().hideCol("xiaoshoumaoli");
                $("#grid").setGridParam().hideCol("maolilv");
            }

			var startdate = $('#startdate').val();
			var enddate = $('#enddate').val();
			var user_id = $('#user_id').val();//选择客户
			var goods_id = $('#goods_id').val();//选择商品
			var goods_category_id = $('#goods_category_id').val();//选择商品类别
			var store_id = $('#store_id').val();//选择仓库
			$("div.grid-subtitle").text("日期: " + startdate + " 至 " + enddate);

			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: { 'ajax': '100', 'startdate': startdate, 'enddate': enddate, 'user_id': user_id, 'goods_id': goods_id,'goods_category_id':goods_category_id,'store_id':store_id}, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
		});



		//alert("1111");
		$("#grid").jqGrid({
			url: '/sales/Salessummarygoods/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			width: '100%',
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["id","商品类别", "商品编号", "商品名称", "商品条码", "规格型号", "仓库", "副单位", "副单位数", "基本单位", "基本数量", "单价", "含税单价", "销售收入", "税额", "价税合计", "单位成本" ,"销售成本" ,"销售毛利" ,"毛利率" ,'商品ID','仓库id'],
			colModel: [
				{ name: 'a_id', hidden: true },
				{ name: 'goods_cate', index: '', width: 80, label: "商品类别" },
				{ name: 'goods_sn', index: '', width: 100, label: "商品编号" },
				{ name: 'goods_name', index: '', width: 200, label: "商品名称" },
				{ name: 'goods_code', index: '', width: 120, label: "商品条码" },
				{ name: 'goods_model', index: '', width: 100, label: "规格型号" },
				{ name: 'store_name', index: '', width: 100, label: "仓库" },
				{ name: '', index: '', width: 100, label: "副单位" },
				{ name: '', index: '', width: 100, label: "副单位数" },
				{ name: 'unit_name', index: '', width: 80, label: "基本单位",align:"center" },
				{ name: 'number', index: '', width: 100, label: "基本数量" ,align:"right"},
				{ name: 'ave_price', index: '', width: 100, label: "单价" ,align:"right" },
				{ name: 'ave_hs_price', index: '', width: 100, label: "含税单价", align:'right', formatter: 'number', formatoptions: { thousandsSeparator: "", decimalPlaces: 2 }},
				{ name: 'ave_jine', index: '', width: 100, label: "销售收入" ,align:"right" },
				{ name: 'ave_tax_e', index: '', width: 100, label: "税额"  ,align:"right"},
				{ name: 'ave_total_price', index: '', width: 100, label: "价税合计" ,align:"right" },
                { name: 'danweichengben', index: 'name asc', width: 80, label: "单位成本", hidden:true  ,align:"right"},
				{ name: 'xiaoshouchengben', index: 'name asc', width: 80, label: "销售成本", hidden:true  ,align:"right"},
				{ name: 'xiaoshoumaoli', index: 'name asc', width: 80, label: "销售毛利", hidden:true ,align:"right" },
				{ name: 'maolilv', index: 'name asc', width: 80, label: "毛利率", hidden:true ,align:"right" },
				{ name: 'goods_id', hidden: true },
				{ name: 'ck', hidden: true },
			],
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置

			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: false,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
            // 合计
			footerrow: true,
			gridComplete: function () {
				var numbers = parseFloat($("#grid").getCol('number', false, 'sum')).toFixed(2);
				var ave_prices = parseFloat($("#grid").getCol('ave_price', false, 'avg')).toFixed(2);
				var ave_hs_prices = parseFloat($("#grid").getCol('ave_hs_price', false, 'avg')).toFixed(2);
				var ave_jines = parseFloat($("#grid").getCol('ave_jine', false, 'sum')).toFixed(2);
				var ave_tax_es = parseFloat($("#grid").getCol('ave_tax_e', false, 'sum')).toFixed(2);
				var ave_total_prices = parseFloat($("#grid").getCol('ave_total_price', false, 'sum')).toFixed(2);
				var danweichengbens = parseFloat($("#grid").getCol('danweichengben', false, 'avg')).toFixed(2);
				var xiaoshouchengbens = parseFloat($("#grid").getCol('xiaoshouchengben', false, 'sum')).toFixed(2);
				var xiaoshoumaolis = parseFloat($("#grid").getCol('xiaoshoumaoli', false, 'sum')).toFixed(2);
				var maolilvs = parseFloat($("#grid").getCol('maolilv', false, 'sum')).toFixed(2);

				$("#grid").footerData('set', { "goods_cate": '合计：', number: numbers, ave_price: ave_prices, ave_hs_price:ave_hs_prices, ave_jine:ave_jines, ave_tax_e:ave_tax_es, ave_total_price:ave_total_prices, danweichengben:danweichengbens, xiaoshouchengben:xiaoshouchengbens, xiaoshoumaoli:xiaoshoumaolis, maolilv:maolilvs });
			
			},
			//双击表格行事件
            ondblClickRow: function(row){
                var rowData = $('#grid').jqGrid('getRowData', row);
                parent.tab.addTabItem({
                    tabid: "purchaseinvPu",
                    text: "销售明细表",
                    url:"/sales/salesdetail/index.html?goods_id="+rowData.goods_id+"&store_id="+rowData.ck+"&doubleclick=1",
                })
                   
            }
		});

		var headH = 0;  //顶部搜索是否展开（1：展开，0：未展开）
		$("#conditions-trigger").click(function () {
			if (headH == 0) {
				headH = 1;
				$("#filterItems").css({ "height": "auto" });
				$(this).html("&nbsp;收起条件<b class='act'></b>");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height()-230-$("#filter-menu").height()+"px");
			} else {
				headH = 0;
				$("#filterItems").css({ "height": "44px" });
				// $("#filterItems").animate({height:'44px'});
				$(this).html("&nbsp;更多条件<b></b>");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height()-230-$("#filter-menu").height()+"px");
			}
		});
		// 点击下拉框其他位置隐藏
		$(document).click(function () {
			$("#filterSelectBox").hide();
		});
		// 阻止冒泡
		$("#goods_type").click(function (event) {
			event.stopPropagation();
		});


	

	});



	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="lopen(\'edit.html?id=' + rowObject.id + '\',\'编辑\',\'400px\',\'300px\')">修改</span> <span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')">删除</span></div>';
	}



	

</script>
{include file="admin@public/footer"/}